import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
//引入element
import ElementUI from 'element-ui';
//引入element ui样式
import 'element-ui/lib/theme-chalk/index.css';
//引入fragement解决菜单收缩时，文字不能隐藏的问题
import Fragment from 'vue-fragment'
Vue.use(Fragment)


Vue.use(ElementUI)
Vue.config.productionTip = false
router.beforeEach((to,from,next)=>{
  //to 将要进入的路由
  //form  将要离开的路由
  //next  让路由继续执行
  //获取当前打开的选项卡
  store.commit('getTabs');
  //设置当前激活的选项卡
  store.commit('setActiveTabs',to.name);
  //解决刷新之后菜单数据不存在的问题
  let menuData=sessionStorage.getItem('menuList');
  if (to.path==='/login'){
    if (menuData){
      next({path:'/home'})
    }else {
      next();
    }
  }else {
    if (!menuData&&to.name!=='login'){
      next({path:'/login'})
    }else{
      if (store.state.MenuStore.menu_data.login==0){
        store.commit('getMenuList',router)
        next({path:to.path})
      }else {
        next();
      }
    }


  }





})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
